<template>
    <div>
        <div>
            <el-button @click="onSignIn">用户签到</el-button>
        </div>
        <div>
            用户的积分：{{ user.userScore }}
        </div>
    </div>
</template>

<script setup lang="ts">
import { getUserInfo,signIn } from "@/api/api";
import { ElMessage } from "element-plus";
import { onMounted, ref } from "vue";

const user = ref({
    userScore: 0, // 用户的积分
});


// 用户签到
const onSignIn = () => {
    signIn().then((res) => {
        if (res.data.code == 200) {
            //loadUserInfo();
            user.value = res.data.data;
            ElMessage.success(res.data.msg);
        }
        else {
            ElMessage.error(res.data.msg);
        }
    });
}

// 获取用户信息
const loadUserInfo = () => {
    getUserInfo().then((res) => {
        if (res.data.code == 200) {
            user.value = res.data.data;
        }
    });
};



onMounted(() => { 
    loadUserInfo();
})

</script>

<style scoped>

</style>